/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ipccenter.security;

import javax.ejb.EJB;
import javax.servlet.ServletContext;
import org.apache.shiro.authc.credential.DefaultPasswordService;
import org.apache.shiro.authc.credential.PasswordMatcher;
import org.apache.shiro.authc.credential.PasswordService;
import org.apache.shiro.mgt.RealmSecurityManager;
//import org.apache.shiro.web.env.EnvironmentLoaderListener;
/**
 *
 * @author sm-ni_000
 */
public class CustomEnvironmentLoaderListener /*extends EnvironmentLoaderListener*/ {

    @EJB
    private MyRealm myRealm;

    //@Override
    protected WebEnvironment createEnvironment(ServletContext pServletContext) {
        WebEnvironment environment = super.createEnvironment(pServletContext);
        RealmSecurityManager rsm = (RealmSecurityManager) environment.getSecurityManager();
        PasswordService passwordService = new DefaultPasswordService();
        PasswordMatcher passwordMatcher = new PasswordMatcher();
        passwordMatcher.setPasswordService(passwordService);
        myRealm.setCredentialsMatcher(passwordMatcher);
        rsm.setRealm(myRealm);
        ((DefaultWebEnvironment) environment).setSecurityManager(rsm);
        return environment;
    }
}

